home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / xml / ReaderContext.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  3.6 KB  |  151 lines

  1. package com.extensibility.xml;
  2.  
  3. import com.extensibility.util.Debug;
  4. import java.io.BufferedReader;
  5. import java.io.EOFException;
  6. import java.io.IOException;
  7. import java.io.Reader;
  8. import java.io.StringReader;
  9.  
  10. final class ReaderContext implements Cloneable, ParserException.Context {
  11.    public static final int UNKNOWN = 0;
  12.    public static final int TYPE_MAIN_DOCUMENT = 1;
  13.    public static final int TYPE_INTERNAL_GE = 2;
  14.    public static final int TYPE_EXTERNAL_GE = 3;
  15.    public static final int TYPE_INTERNAL_PE = 4;
  16.    public static final int TYPE_EXTERNAL_PE = 5;
  17.    public static final int TYPE_PADDING = 6;
  18.    public static final int TYPE_MAX = 6;
  19.    Reader readThis;
  20.    Reader reader;
  21.    int type;
  22.    String name;
  23.    String value;
  24.    URI uri;
  25.    int lineNo;
  26.    int charNo;
  27.    int unreadChar;
  28.  
  29.    public ReaderContext(int var1, URI var2) throws IOException {
  30.       this(var2.createReader(), var1, "", "", var2);
  31.       Debug.assert(var1 == 1, "Constructor should only be used for main document. From then on, a URI should be given.");
  32.       this.readThis = new BufferedReader(this.reader);
  33.    }
  34.  
  35.    public ReaderContext(URI var1, int var2, String var3, URI var4) throws IOException {
  36.       this(var1.createReader(), var2, var3, "", var4);
  37.       Debug.assert(var2 == 1 || var2 == 3 || var2 == 5 || var2 == 6, "Constructor should only be used for external references.");
  38.       this.checkType();
  39.       this.readThis = new BufferedReader(this.reader);
  40.    }
  41.  
  42.    public ReaderContext(String var1, int var2, String var3, String var4, URI var5) {
  43.       this((Reader)(new StringReader(var1)), var2, var3, var4, var5);
  44.       this.checkType();
  45.    }
  46.  
  47.    private ReaderContext(Reader var1, int var2, String var3, String var4, URI var5) {
  48.       this.lineNo = 1;
  49.       this.charNo = 1;
  50.       this.reader = var1;
  51.       this.readThis = this.reader;
  52.       this.type = var2;
  53.       this.name = var3;
  54.       this.value = var4;
  55.       this.uri = var5;
  56.       this.checkType();
  57.    }
  58.  
  59.    public Object clone() {
  60.       Object var1;
  61.       try {
  62.          var1 = super.clone();
  63.       } catch (Exception var4) {
  64.          Object var3 = null;
  65.          return var3;
  66.       }
  67.  
  68.       this.reader = null;
  69.       return var1;
  70.    }
  71.  
  72.    public URI getURI() {
  73.       return this.uri;
  74.    }
  75.  
  76.    public String getValue() {
  77.       return this.value;
  78.    }
  79.  
  80.    public int getType() {
  81.       this.checkType();
  82.       return this.type;
  83.    }
  84.  
  85.    public String getName() {
  86.       return this.name;
  87.    }
  88.  
  89.    protected void checkType() {
  90.       Debug.assert(this.type >= 1 && this.type <= 6, String.valueOf("Invalid type: ").concat(String.valueOf(this.type)));
  91.    }
  92.  
  93.    public void close() {
  94.       try {
  95.          if (this.reader != null) {
  96.             this.reader.close();
  97.          }
  98.       } catch (IOException var2) {
  99.       }
  100.  
  101.    }
  102.  
  103.    public int unread(char var1) throws EOFException {
  104.       if (this.unreadChar != 0) {
  105.          throw new EOFException();
  106.       } else {
  107.          this.unreadChar = var1;
  108.          return 0;
  109.       }
  110.    }
  111.  
  112.    public int read() throws IOException {
  113.       int var1;
  114.       if (this.unreadChar != 0) {
  115.          var1 = this.unreadChar;
  116.          this.unreadChar = 0;
  117.       } else {
  118.          var1 = this.readThis.read();
  119.          if (var1 == 10) {
  120.             ++this.lineNo;
  121.             this.charNo = 0;
  122.          } else {
  123.             ++this.charNo;
  124.          }
  125.       }
  126.  
  127.       return var1;
  128.    }
  129.  
  130.    public int getLine() {
  131.       return this.lineNo;
  132.    }
  133.  
  134.    public int getColumn() {
  135.       return this.charNo;
  136.    }
  137.  
  138.    public boolean isInternal() {
  139.       this.checkType();
  140.       return this.type == 2 || this.type == 4;
  141.    }
  142.  
  143.    public void mark(int var1) throws IOException {
  144.       this.readThis.mark(var1);
  145.    }
  146.  
  147.    public void reset() throws IOException {
  148.       this.readThis.reset();
  149.    }
  150. }
  151.